
package org.mushroomdb.security.queries;



import org.mushroomdb.engine.EvaluationEngine;
import org.mushroomdb.exception.EvaluationEngineException;
import org.mushroomdb.query.Query;
import org.mushroomdb.security.SecurityService;
import org.mushroomdb.security.User;
import org.mushroomdb.service.ServiceManager;

/**
 *Representation of the "Drop User" Query 
 */
public class DropUserQuery extends SecurityQuery {
    private String userName;
    
    /**
     * @param queryString
     */
    public DropUserQuery(String query) {
        query = query.substring(query.indexOf("USER") + 4).trim();
        this.userName = query.substring(0, query.indexOf(" ")).trim();

    }

    public Object execute(EvaluationEngine evaluationEngine) {
        
        SecurityService service = (SecurityService) ServiceManager.getInstance().getService(SecurityService.class);
        User user=null;
        user = service.getUserByName(this.userName);
        service.dropUser(user);
        return user;
    }

}
